package com.liqi.items.service.impl;

import com.liqi.common.utils.DateUtils;
import com.liqi.items.domain.TRelFormSubject;
import com.liqi.items.domain.TRelServiceSubject;
import com.liqi.items.mapper.TRelServiceSubjectMapper;
import com.liqi.items.service.ITRelServiceSubjectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * 主题事项关联Service业务层处理
 *
 * @author xiaoli
 * @date 2022-04-08
 */
@Service
public class TRelServiceSubjectServiceImpl implements ITRelServiceSubjectService
{
    @Autowired
    private TRelServiceSubjectMapper tRelServiceSubjectMapper;

    /**
     * 查询主题事项关联
     *
     * @param id 主题事项关联主键
     * @return 主题事项关联
     */
    @Override
    public TRelServiceSubject selectTRelServiceSubjectById(Long id)
    {
        return tRelServiceSubjectMapper.selectTRelServiceSubjectById(id);
    }

    /**
     * 查询主题事项关联列表
     *
     * @param tRelServiceSubject 主题事项关联
     * @return 主题事项关联
     */
    @Override
    public List<TRelServiceSubject> selectTRelServiceSubjectList(TRelServiceSubject tRelServiceSubject)
    {
        return tRelServiceSubjectMapper.selectTRelServiceSubjectList(tRelServiceSubject);
    }

    /**
     * 新增主题事项关联
     *
     * @param tRelServiceSubject 主题事项关联
     * @return 结果
     */
    @Override
    public int insertTRelServiceSubject(TRelServiceSubject tRelServiceSubject)
    {
        tRelServiceSubject.setCreateTime(DateUtils.getNowDate());
        return tRelServiceSubjectMapper.insertTRelServiceSubject(tRelServiceSubject);
    }

    /**
     * 修改主题事项关联
     *
     * @param tRelServiceSubject 主题事项关联
     * @return 结果
     */
    @Override
    public int updateTRelServiceSubject(TRelServiceSubject tRelServiceSubject)
    {
        int i = 0;
        TRelServiceSubject entity = tRelServiceSubjectMapper.selectTRelServiceSubjectByServiceSubjectCode(tRelServiceSubject);
        if (entity != null) {
            entity.setUpdateTime(DateUtils.getNowDate());
            entity.setSort(tRelServiceSubject.getSort());
            return tRelServiceSubjectMapper.updateTRelServiceSubject(entity);
        }
        return i;
    }

    /**
     * 批量删除主题事项关联
     *
     * @param ids 需要删除的主题事项关联主键
     * @return 结果
     */
    @Override
    public int deleteTRelServiceSubjectByIds(Long[] ids)
    {
        return tRelServiceSubjectMapper.deleteTRelServiceSubjectByIds(ids);
    }

    /**
     * 删除主题事项关联信息
     *
     * @param id 主题事项关联主键
     * @return 结果
     */
    @Override
    public int deleteTRelServiceSubjectById(Long id)
    {
        return tRelServiceSubjectMapper.deleteTRelServiceSubjectById(id);
    }

    /**
     * 通过主题代码 查询主题事项关联列表
     *
     * @param subjectCode 主题代码
     * @return 主题事项关联
     */
    @Override
    public List<TRelServiceSubject> selectTRelServiceSubjectBySubjectCode(String subjectCode) {
        return tRelServiceSubjectMapper.selectTRelServiceSubjectBySubjectCode(subjectCode);
    }

    /**
     * 批量新增主题事项关联
     *
     * @param tRelServiceSubjectList
     * @return
     */
    @Override
    @Transactional
    public int batchInsertTRelServiceSubject(List<TRelServiceSubject> tRelServiceSubjectList) {
        int i = 0;
        for (TRelServiceSubject tRelServiceSubject : tRelServiceSubjectList) {
            i = tRelServiceSubjectMapper.insertTRelServiceSubject(tRelServiceSubject);
        }
        return i;
    }
    /**
     * 批量新增主题表单关联
     *
     * @param tRelFormSubjectList
     * @return
     */
    @Override
    @Transactional
    public int batchInsertTRelFormSubject(TRelFormSubject tRelFormSubjectList) {
    	tRelFormSubjectList.setCreateTime(DateUtils.getNowDate());

    	return tRelServiceSubjectMapper.insertTRelFormSubject(tRelFormSubjectList);
    }
    
    @Override
    @Transactional
    public int batchDeleteTRelServiceSubject(List<TRelServiceSubject> tRelServiceSubjectList) {
        int i = 0;
        for (TRelServiceSubject tRelServiceSubject : tRelServiceSubjectList) {
            TRelServiceSubject entity = tRelServiceSubjectMapper.selectTRelServiceSubjectByServiceSubjectCode(tRelServiceSubject);
            if (entity != null) {
                i = tRelServiceSubjectMapper.deleteTRelServiceSubjectById(entity.getId());
            }
        }
        return i;
    }
    
    @Override
    public int batchDeleteTRelFormSubject(Long[] ids) {
        return tRelServiceSubjectMapper.deleteTRelFormSubjectById(ids);
    }

    @Override
    public TRelServiceSubject selectTRelServiceSubjectByServiceSubjectCode(TRelServiceSubject tRelServiceSubject) {
        return tRelServiceSubjectMapper.selectTRelServiceSubjectByServiceSubjectCode(tRelServiceSubject);
    }

    @Override
    public int deleteTRelServiceSubjectBySubjectCode(Map<String,Object> map) {
        return tRelServiceSubjectMapper.deleteTRelServiceSubjectBySubjectCode(map);
    }

	@Override
	public List<TRelFormSubject> selectTRelFormSubjectByServiceSubjectCode(String subjectCode) {
        return tRelServiceSubjectMapper.selectTRelFormSubjectByServiceSubjectCode(subjectCode);
	}

	@Override
	public List<TRelFormSubject> selectlistExcludeFormByServiceSubjectCode(Map<String, Object> resultmap) {
		return     tRelServiceSubjectMapper.selectlistExcludeFormByServiceSubjectCode(resultmap);

	}
    /**
     * 修改主题表单关联
     *
     * @param tRelServiceSubject 主题表单关联
     * @return 结果
     */
    @Override
    public int updateTRelFormSubject(TRelFormSubject tRelFormSubject) {
            return tRelServiceSubjectMapper.updateTRelFormSubject(tRelFormSubject);
}
    
    @Override
    public List<String> getFormKeyByIds(Long[] ids) {
        return tRelServiceSubjectMapper.getFormKeyByIds(ids);
    }

}
